package com.lemner.www.hongyu.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lemner.www.hongyu.Bean.FinishorderBean;
import com.lemner.www.hongyu.R;

/**
 * Created by 小博 on 2017/11/10.
 */

public class FinishorderAdapter extends RecyclerView.Adapter{
    private Context context;
    private LayoutInflater layoutInflater;
    private FinishorderBean.DataBean bean;
    public FinishorderAdapter(Context context) {
        this.context = context;
        this.layoutInflater = layoutInflater.from(context);
    }
    public void setBean(FinishorderBean.DataBean bean) {
        this.bean = bean;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_finishorder, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        FinishorderBean.DataBean.ListBean date=bean.getList().get(position);
        ViewHolder holder1=(ViewHolder) holder;
        if(date==null){
            return ;
        }
        holder1.tv_phone2.setText(date.getOwner_phone());
        holder1.tv_address2.setText(date.getAddress());
        holder1.tv_cause2.setText(date.getCause());
        holder1.tv_worker2.setText(date.getOwner_name());
        holder1.tv_ordernum2.setText(date.getOrder_number());
    }

    @Override
    public int getItemCount() {
        if(bean==null)
            return 0;
        else
            return bean.getList().size();
    }

    public class  ViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_ordernum2,tv_worker2,tv_phone2,tv_address2,tv_cause2;
        public ViewHolder(View itemView) {
            super(itemView);
            tv_address2=(TextView) itemView.findViewById(R.id.tv_address2);
            tv_ordernum2=(TextView) itemView.findViewById(R.id.tv_ordernum2);
            tv_worker2=(TextView) itemView.findViewById(R.id.tv_worker2);
            tv_cause2=(TextView) itemView.findViewById(R.id.tv_cause2);
            tv_phone2=(TextView) itemView.findViewById(R.id.tv_iphone2);
        }
    }

}
